package com.hry.store.cms.service.impl;

import com.hry.store.cms.dao.HotProductMapper;
import com.hry.store.cms.pojo.HotProduct;
import com.hry.store.cms.service.HotProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotProductServiceImpl implements HotProductService {
    @Autowired
    private HotProductMapper hotProductMapper;
    /**
     * 根据一级标题查询轮播图商品名称
     * @param topCategoryId
     * @return
     */
    @Override
    public List<HotProduct> getHotProductByTopCategory(Integer topCategoryId) {
        return hotProductMapper.getHotProductByTopCategory(topCategoryId);
    }

    /**
     * 添加热门商品名称
     * @param topCategory
     * @param productName
     * @return
     */
    @Override
    public int addSecondCategory(Integer topCategory, String productName) {
        HotProduct hotProduct = new HotProduct();
        hotProduct.setTopCategoryId(topCategory);
        hotProduct.setStatus(1);
        hotProduct.setIsHotProduct(true);
        hotProduct.setSecondCategoryName(productName);
        return hotProductMapper.insertSelective(hotProduct);
    }

    /**
     * 插入轮播图地址
     * @param secondCategoryId
     * @param url
     */
    @Override
    public void addLunBoImage(Integer secondCategoryId, String url, String prodcutDesc) {
        HotProduct hotProduct = new HotProduct();
        hotProduct.setLunboImage(url);
        hotProduct.setSecondCategoryId(secondCategoryId);
        hotProduct.setProductDesc(prodcutDesc);
        hotProductMapper.updateByPrimaryKeySelective(hotProduct);
    }
}
